//
//  CLStatus.swift
//  CLWeibo
//
//  Created by 陈亮 on 16/7/12.
//  Copyright © 2016年 陈亮. All rights reserved.
//

import UIKit

class CLStatus: NSObject {

    //发布微博时间
    var created_at:String?
    //微博id
    var id:Int64 = 0
    //微博内容
    var text:String?
    //微博来源
    var source:String?
    //关注用户对象
    var user:CLUser?
    //转发数
    var reposts_count:Int = 0
    //评论数
    var comments_count:Int = 0
    //赞
    var attitudes_count:Int = 0
    //转发微博对象
    var reweeted_status:CLStatus?
    //配图信息
    var pic_urls:[CLStatusPictureInfo]?
    //kvc
    init(dic :[String :AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dic)
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String :AnyObject] else {
                return
            }
            user = CLUser(dic:dic)
        }else if key == "retweeted_status" {
            guard let dic = value as? [String:AnyObject] else{
                return
            }
            reweeted_status = CLStatus(dic: dic)
        }else if key == "pic_urls" {
            guard let dicArray = value as? [[String:AnyObject]] else {
                return
            }
            var tempArray = [CLStatusPictureInfo]()
            for dic in dicArray {
               let pictureInfo = CLStatusPictureInfo(dic:dic)
                tempArray.append(pictureInfo)
            }
            //设置自定义属性
            pic_urls = tempArray
        }else {
            super.setValue(value, forKey: key)
        }
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
